<template>
    <Table 
        border
        stripe
        :columns="columns"
        :data="data.data"
        :loading="data.isLoading">
    </Table>
</template>
<script>
import filterTime from '@/filters/filterTime.js'
import filterApp from '@/filters/filterApp.js'

export default {
    name: 'AccountListView.vue',
    props: ['data'],
    data() {
        return {
            columns: [
                {
                    title: '账户',
                    key: 'account',
                    width: 250,
                    tooltip: true,
                    align: 'center'
                },
                {
                    title: '启用',
                    key: 'isEnable',
                    width: 250,
                    tooltip: true,
                    align: 'center',
                    render: function(h,params){
                        return h('span',filterApp.formatEnable(params.row.isEnable));
                    }
                },
                {
                    title: '创建时间',
                    key: 'createTime',
                    width: 220,
                    tooltip: true,
                    align: 'center',
                    render: function(h,params){
                        // params 包含 row、column 和 index，分别指当前行数据，当前列数据，当前行索引
                        return h('span',filterTime.formatTimestamp(params.row.createTime));
                    }
                },
                {
                    title: '操作',
                    key: 'action',
                    align: 'center',
                    render: (h, params) => {
                        let array = new Array();
                        let editBtn = h('Button', {
                            props: {
                                type: 'primary',
                                size: 'small'
                            },
                            style: {
                                marginRight: '5px'
                            },
                            on: {
                                click: () => {
                                    this.onAction({action: 'edit', data: params.row})
                                }
                            }
                        }, '编辑');
                        let delBtn = h('Button', {
                            props: {
                                type: 'error',
                                size: 'small'
                            },
                            style: {
                                marginRight: '5px'
                            },
                            on: {
                                click: () => {
                                    this.onAction({action: 'remove', data: params.row})
                                }
                            }
                        }, '删除');
                        let enableBtn = h('Button', {
                            props: {
                                type: 'primary',
                                size: 'small'
                            },
                            style: {
                                marginRight: '5px'
                            },
                            on: {
                                click: () => {
                                    this.onAction({action: 'enable', data: params.row})
                                }
                            }
                        }, '启用');
                        let disableBtn = h('Button', {
                            props: {
                                type: 'primary',
                                size: 'small'
                            },
                            style: {
                                marginRight: '5px'
                            },
                            on: {
                                click: () => {
                                    this.onAction({action: 'disable', data: params.row})
                                }
                            }
                        }, '禁用');

                        array.push(editBtn);
                        array.push(delBtn);
                        if(params.row.isEnable==1){
                           array.push(disableBtn);
                        }else {
                            array.push(enableBtn);
                        }
                        return h('div', array);
                    }
                }
            ]
        }
    },
    methods: {
        onAction (actionData) {
            this.$emit('on-action',actionData);
        }
    }
}
</script>
<style lang="less" scoped>

</style>



